<template>
    <div>
        <el-dialog :visible.sync="value" :show-close="false" center >
            <el-form ref="form" :model="data" hide-required-asterisk status-icon>
                <el-row :gutter="20">
                    <el-col :span="12">
                        <el-form-item prop="jyId" label="指定教员" :rules="[{required:true,message:'请选择教员',trigger:'change'}]">
                            <el-select v-model="data.jyId" placeholder="请选择教员">
                                <el-option v-for="jy in jyList" :key="jy.id" :value="jy.id" :label="jy.nickName"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item prop="bzrId" label="指定班主任" :rules="[{required:true,message:'请选择班主任',trigger:'change'}]">
                            <el-select v-model="data.bzrId" placeholder="请选择班主任">
                                <el-option v-for="bzr in bzrList" :key="bzr.id" :value="bzr.id" :label="bzr.nickName"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <template slot="footer">
                <el-button type="primary" icon="el-icon-plus" v-loading.fullscreen.lock="fullscreenLoading" @click="handleSubmit">提交</el-button>
            </template>
        </el-dialog>
    </div>
</template>

<script>

    import { searchTeachers } from '@/api/principal/school-manager/teacher'
    import { appointTeachers } from '@/api/quality/classes'
    export default {
        name: "classes-appoint-teacher-child",
        data(){
            return {
                parent:{},
                value:false,
                fullscreenLoading:false,
                jyList:[],
                bzrList:[],
                data:{}
            }
        },
        watch:{
            value(data){
                if(data){
                    this.fullscreenLoading = true;
                    searchTeachers().then(res=>{
                        this.jyList = res.data.data.jyList;
                        this.bzrList = res.data.data.bzrList;
                        this.fullscreenLoading = false;
                    })
                }
            }
        },
        methods:{
            handleSubmit(){
                this.$refs['form'].validate(valid=>{
                    if(valid){

                        this.$confirm("确定要提交吗?","温馨提示",{type:'warning'}).then(()=>{
                            let data = {};
                            data.classesId = this.parent.id;
                            let params = Object.assign(data,this.data);
                            console.log(params);
                            this.fullscreenLoading = true;
                            appointTeachers(params).then(res=>{
                                this.value = false;
                                this.fullscreenLoading = false;
                                this.$parent.getClassesList(this.$parent.params);
                            })
                        });
                    }else{
                        return false;
                    }
                });
            }
        }
    }
</script>

<style scoped>

</style>